import request from '@/utils/request'
import qs from 'qs'


//数据集列表树
export  function querytree(data){
  return request({
    url:'/system//dataset/querytree',
    method:'post',
    data
  })
}

//获取数据集树(全加载)
export  function queryAllTree(data){
  return request({
    url:'/system//dataset/queryAllTree',
    method:'post',
    data
  })
}

//新增树分类
export function treeAdd(data){
  return request({
    url:'/system/datesettype/add',
    method:'post',
    data
  })
}
//重命名树
export function treeEdit(data){
  return request({
    url:'/system/datesettype/edit',
    method:'post',
    data
  })
}

//删除树
export function treeDelete(data){
  return request({
    url:'/system/datesettype/remove',
    method:'post',
    data
  })
}
//删除树校验
export function deleteCheck(data){
  return request({
    url:'/system/datesettype/deleteCheck',
    method:'post',
    data
  })
}

//查询数据集列表
export function getDataSetList(data){
  return request({
    url:'/system/dataset/list',
    method:'get',
    params: data
  })
}

//删除数据集
export function remove(data){
  return request({
    url:'/system/dataset/remove',
    method:'post',
    data
  })
}

// 删除数据前校验
export function deleteForCheck(data) {
  return request({
    url: '/system/dataset/deleteCheck',
    method: 'post',
    data: data
  })
}
//新增数据集
export function addDataSet(data){
  return request({
    url: '/system/dataset/add',
    method: 'post',
    headers: {
      'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8'
    },
    data: qs.stringify(data)
  })
}

//根据id获取数据集数据
export function getInfo(data){
  return request({
    url:'/system/dataset/getInfo',
    method:'get',
    params: data
  })
}

//修改数据集
export function editDataSet(data){
  return request({
    url: '/system/dataset/edit',
    method: 'post',
    headers: {
      'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8'
    },
    data: qs.stringify(data)
  })
}

//数据源列表获取
export function getDataSourceList(data){
  return request({
    url:'/system/report/datasource/list',
    method:'get',
    params: data
  })
}

//数据源列表获取
export function querySourceList(data){
  return request({
    url:'/system/report/datasource/querySourceList',
    method:'get',
    params: data
  })
}



//根据数据源id获取表数据
export function getTableByDataSouce(data){
  return request({
    url:'/system/report/datasource/getTableByDataSouce',
    method:'post',
    data
  })
}

//根据表获取表字段
export function getTableField(data){
  return request({
    url:'/system/report/datasource/getTableField',
    method:'post',
    data
  })
}

//获取字段配置数据
export function inputOutputFields(data){
  return request({
    url:'/system/report/datasource/inputOutputFields',
    method:'post',
    data
  })
}

//ES根据数据源id获取字段列表
export function subgroup_selectIndexList(data) {
  return request({
    url: '/system/reports/component/selectIndexList',
    method: 'post',
    data: data
  })
}

// //根据表获取表字段(适配mysql和ES数据源)
// export function getTableField(data) {
//   return request({
//     url: '/system/report/datasource/getTableField',
//     method: 'post',
//     data: data
//   })
// }


// 获取数据集树形结构 包含节点数据
export function queryAllTreeWithData(data){
  return request({
    url:'/system/dataset/queryAllTreeWithData',
    method:'post',
    data
  })
}

// 获取数据集 数据和字段信息  部分数据
export function getPreviewReportsData(data) {
  return request({
    url: '/system/reports/component/getPreviewReportsDataNew',
    method: 'post',
    data
  })
}


// 获取数据集 数据和字段信息 全部数据
export function getReportsData(data) {
  return request({
    url: '/system/reports/component/getReportsData',
    method: 'post',
    data
  })
}

// 检测sql输入正确性
export function checkSql(data) {
  return request({
    url: '/system/dataset/checksql',
    method: 'post',
    headers: {
      'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8'
    },
    data: qs.stringify(data)
  })
}

// 修改分类
export function editDatasetType(data) {
  return request({
    url: '/system/dataset/editDatasetType',
    method: 'post',
    data
  })
}

// API接口预览
export function transferApi(data) {
  return request({
    url: '/system/dataset/transferApi',
    method: 'post',
    data
  })
}

// API接口预览
export function getApiFieldByUrl(data) {
  return request({
    url: '/system/report/datasource/getApiFieldByUrl',
    method: 'post',
    data
  })
}

// API接口预览
export function queryComponentInfo(data) {
  return request({
    url: '/system/dataset/queryComponentInfo',
    method: 'post',
    data
  })
}

// 根据前一节点获取数据
export function executeChain(data) {
  return request({
    url: '/system/newDataset/executeChain',
    method: 'post',
    data
  })
}


/**
 * 获取数据集 关联的 变量数据
 * @param {*} data 
 * @returns 
 */
export function getDataSetVariable(data){
  return request({
    url:'/system/dataset/queryVariable',
    method:'get',
    params: data
  })
}
